package com.leagsoft.emm.demo;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.huawei.secoclient.sslvpn.ConstValue;
import com.huawei.secoclient.sslvpn.VpnUtils;
import com.leagsoft.emm.demo.util.ToastUtil;

/**
 * 修改密码界面
 */
public class ModifyPasswordActivity extends AppCompatActivity {

    private EditText etOriginalPass;
    private EditText etNewPass;
    private EditText etConfirmPass;
    private Button btnCommit;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_modify_password);
        initView();
    }

    private void initView() {
        btnCommit = (Button) findViewById(R.id.btn_commit);

        etConfirmPass = (EditText) findViewById(R.id.et_again_old_password);
        etNewPass = (EditText) findViewById(R.id.et_new_password);
        etOriginalPass = (EditText) findViewById(R.id.et_old_password);

        btnCommit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String originalPass = etOriginalPass.getText().toString().trim();
                String newPass = etNewPass.getText().toString().trim();
                String confirmPass = etConfirmPass.getText().toString().trim();
                boolean success = VpnUtils.modifyPassword(originalPass, newPass, confirmPass, code -> {
                    if (code == ConstValue.MODIFY_PASS_SUCCESS) {
                        ToastUtil.show(ModifyPasswordActivity.this, "修改密码成功 响应码:" + code);
                        finish();
                    } else if (code == ConstValue.MODIFY_OLD_PASS_ERROR) {
                        ToastUtil.show(ModifyPasswordActivity.this, "修改密码时旧密码错误 响应码:" + code);
                    } else if (code == ConstValue.MODIFY_PASS_IS_LOW_ERROR) {
                        ToastUtil.show(ModifyPasswordActivity.this, "修改密码时新密码不符合低密码策略 响应码:" + code);
                    } else if (code == ConstValue.MODIFY_PASS_IS_MIDDLE_ERROR) {
                        ToastUtil.show(ModifyPasswordActivity.this, "修改密码时新密码不符合中密码策略 响应码:" + code);
                    } else if (code == ConstValue.MODIFY_PASS_IS_HIGH_ERROR) {
                        ToastUtil.show(ModifyPasswordActivity.this, "修改密码时新密码不符合高密码策略 响应码:" + code);
                    } else if (code == ConstValue.MODIFY_PASS_OTHER_ERROR_CODE) {
                        ToastUtil.show(ModifyPasswordActivity.this, "修改密码时新密码其他未知错误 响应码:" + code);
                    } else if (code == ConstValue.MODIFY_PASS_PASSWORD_WRONGFUL) {
                        ToastUtil.show(ModifyPasswordActivity.this, "请输入正确的密码 响应码:" + code);
                    } else if (code == ConstValue.MODIFY_PASS_NEW_NO_EQUALS_CONFIRMPASS) {
                        ToastUtil.show(ModifyPasswordActivity.this, "新密码和确认密码不一致 响应码:" + code);
                    } else if (code == ConstValue.MODIFY_PASS_NEW_EQUALS_OLD) {
                        ToastUtil.show(ModifyPasswordActivity.this, "新密码和旧密码一致 响应码:" + code);
                    } else if (code == ConstValue.MODIFY_PASS_LEN_ERROR) {
                        ToastUtil.show(ModifyPasswordActivity.this, "密码长度不对 响应码:" + code);
                    }else {
                        ToastUtil.show(ModifyPasswordActivity.this, "不支持修改密码 响应码:" + code);
                    }
                });

                if (!success) {
                    ToastUtil.show(ModifyPasswordActivity.this, "修改密码构建失败");
                }

            }
        });
    }
}
